#ifndef POLYNOMIAL_H
#define POLYNOMIAL_H

#include <iostream>
#include <vector>
using namespace std;

class PolynomialCalculator {
private:
    struct Term {
        int coefficient;
        int exponent;
        Term(int coef, int exp) : coefficient(coef), exponent(exp) {}
    };
    
    vector<Term> terms;

public:
    void addTerm(int coef, int exp) {
        terms.push_back(Term(coef, exp));
        cout << "添加项: " << coef << "x^" << exp << endl;
    }
    
    void display() {
        if (terms.empty()) {
            cout << "多项式为空" << endl;
            return;
        }
        
        cout << "多项式: ";
        for (size_t i = 0; i < terms.size(); ++i) {
            if (terms[i].coefficient > 0 && i > 0) {
                cout << " + ";
            } else if (terms[i].coefficient < 0) {
                cout << " - ";
            }
            
            int absCoef = abs(terms[i].coefficient);
            if (terms[i].exponent == 0) {
                cout << absCoef;
            } else if (terms[i].exponent == 1) {
                cout << absCoef << "x";
            } else {
                cout << absCoef << "x^" << terms[i].exponent;
            }
        }
        cout << endl;
    }
    
    void clear() {
        terms.clear();
        cout << "多项式已清空" << endl;
    }

};

#endif
